package com.guigu.www.erp.dehao.controller;

import com.guigu.www.erp.common.pojo.MManufacture;
import com.guigu.www.erp.common.pojo.MProcedureModuling;
import com.guigu.www.erp.common.pojo.MProceduring;
import com.guigu.www.erp.common.pojo.PageVo;
import com.guigu.www.erp.dehao.pojo.User;
import com.guigu.www.erp.dehao.service.DHMProceduringService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/DHMProceduring")
public class DHMProceduringController {
    @Autowired
    private DHMProceduringService service;

    @RequestMapping("/findAllTag01")
    public PageVo<MManufacture> queryManufactureProcedureTag01(Integer pageNum,Integer pageSize) {
        return service.queryManufactureProcedureTag01(pageNum,pageSize);
    }

    @GetMapping("/queryByCheckTag01")
    public Integer queryByCheckTag01() {
        return service.queryByCheckTag01();
    }

    @PostMapping("/insertSelectMProceduring")
    public void insertSelectMProceduring(@RequestBody MProceduring mProceduring) {
        mProceduring.setRegisterTime(new Date().toLocaleString());
        service.insertSelectMProceduring(mProceduring);
        for (MProcedureModuling mProcedureModuling : mProceduring.getMProcedureModulings()) {
            mProcedureModuling.setId(null);
            mProceduring.setParentId(mProceduring.getId());
            service.insertSelectModuling(mProcedureModuling);
        }
    }

    @RequestMapping("/queryManufactureProcedureTag1")
    public PageVo<MManufacture> queryManufactureProcedureTag1(Integer pageNum, Integer pageSize, HttpServletRequest request) {
        User loginUser = (User) request.getSession().getAttribute("loginUser");
        if (loginUser.getRole().getRoleId()==4){
            return null;
        }
       return service.queryManufactureProcedureTag1(pageNum,pageSize);
    }

    @GetMapping("/queryByCheckTag1AndProcedure1")
    public Integer queryByCheckTag1AndProcedure1() {
        return service.queryByCheckTag1AndProcedure1();
    }

    @PutMapping("/upMProceduringByParentIdAndProId")
    public void upMProceduringByParentIdAndProId(@RequestBody MProceduring mProceduring) {
        mProceduring.setCheckTime(new Date().toLocaleString());
        service.upMProceduringByParentIdAndProId(mProceduring);
    }

    @GetMapping("/queryByParentIdProceduring")
    public MProceduring queryByParentIdProceduring(Integer parentId, String procedureId) {
        return service.queryByParentIdProceduring(parentId, procedureId);
    }

    @RequestMapping("/findAllMManufactureByCheckTag1")
    public PageVo<MManufacture> findAllMManufactureByCheckTag1(Integer pageNum, Integer pageSize,String manufactureId) {
       return service.findAllMManufactureByCheckTag1(pageNum, pageSize,manufactureId);
    }

    @GetMapping("/queryManufactureCountBy12")
    public Integer queryManufactureCountBy12() {
        return service.queryManufactureCountBy12();
    }

}
